#!/bin/bash
listen=8080
ip=192.168.188.192
rpm -qa|grep httpd
if [ $? -ne 0 ];then
	echo "安装apache"
else
	echo "rpm -e 包名 --nodeps 用此命令删除"
	exit 0
fi
echo "正在安装apache"
yum install httpd -y > /dev/null 2>&1 
if [ $? -eq 0 ];then
	echo "apache安装成功"
else
	echo "安装apache报错请查看"
fi
sed -i 's/^Listen/#&/g' /etc/httpd/conf/httpd.conf
echo  Listen $listen >>  /etc/httpd/conf/httpd.conf
systemctl  enable httpd && systemctl  start httpd
if  [ $? -eq 0 ];then
echo "安装并修改端口正常...."
else 
exit 0
fi 
echo ""
echo "开始部署网页"
echo "正在为您导入配置文件"
touch /etc/httpd/conf.d/$ip.conf && mkdir -p /var/www/html/$ip && cat /root/apache/apache_config.txt >> /etc/httpd/conf.d/$ip.conf  && cp -r /root/apache/sound_code/* /var/www/html/$ip
if  [ $? -eq 0 ];then
echo "配置文件及文件夹创建成功"
else
echo "配置文件及文件夹有失败"
exit 0
fi
sed -i '/^<VirtualHost/c\<VirtualHost *:'$listen'>' /etc/httpd/conf.d/$ip.conf
sed -i '/^ServerName/c\ServerName '$ip'' /etc/httpd/conf.d/$ip.conf
sed -i '/^DocumentRoot/c\DocumentRoot /var/www/html/'$ip'' /etc/httpd/conf.d/$ip.conf
systemctl  restart httpd
if  [ $? -eq 0 ];then
echo "域名及端口和服务成功"
else
echo "域名及端口和重启服务有失败"
exit 0
fi
echo "可以试试访问IP加端口或者域名"

